<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">  
    <title>My JSP 'uploadAllPic.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript" src="js/jquery-1.7.1.js"></script>
	<script type="text/javascript">
		UpLoadFileCheck = function() {
		this.AllowExt = ".jpg,.gif,.png,.bmp";//允许上传的文件类型 0为无限制 每个扩展名后边要加一个"," 小写字母表示 
		this.AllowImgFileSize = 0;//允许上传文件的大小 0为无限制 单位：KB 
		this.AllowImgWidth = 0;//允许上传的图片的宽度 0为无限制　单位：px(像素) 
		this.AllowImgHeight = 0;//允许上传的图片的高度 0为无限制　单位：px(像素) 
		this.ImgObj = new Image();
		this.ImgFileSize = 0;
		this.ImgWidth = 0;
		this.ImgHeight = 0;
		this.FileExt = "";
		this.ErrMsg = "";
		this.IsImg = false;//全局变量
	}
	UpLoadFileCheck.prototype.CheckExt = function(obj) {
		this.ErrMsg = "";
		this.ImgObj.src = obj.value;
		var id = obj.id;
		if (obj.value == "") {
			this.ErrMsg = "/n请选择一个文件";
		} else {
			this.FileExt = obj.value.substr(obj.value.lastIndexOf("."))
					.toLowerCase();
			if (this.AllowExt != 0 && this.AllowExt.indexOf(this.FileExt) == -1)//判断文件类型是否允许上传 
			{
				this.ErrMsg = "该文件类型不允许上传。请上传 " + this.AllowExt
						+ " 类型的文件，当前文件类型为" + this.FileExt;
			}
			var $x = $("#"+id+"+input");//兄弟关系  弟弟必须是div 紧跟着的
			var dinput =$x[0];
			dinput.value="yes";
		}
		if (this.ErrMsg != "") {
			this.ShowMsg(this.ErrMsg, false);
			return false;
		} else
			return this.CheckProperty(obj);
	}
	UpLoadFileCheck.prototype.CheckProperty = function(obj) {
		while (this.ImgObj.readyState != "complete")//
		{
			sleep(1000);//一秒使用图能完全加载    
		}
		if (this.IsImg == true) {
			this.ImgWidth = this.ImgObj.width;//取得图片的宽度 
			this.ImgHeight = this.ImgObj.height;//取得图片的高度
			if (this.AllowImgWidth != 0 && this.AllowImgWidth < this.ImgWidth)
				this.ErrMsg = this.ErrMsg + "图片宽度超过限制。请上传宽度小于"
						+ this.AllowImgWidth + "px的文件，当前图片宽度为" + this.ImgWidth
						+ "px";
			if (this.AllowImgHeight != 0
					&& this.AllowImgHeight < this.ImgHeight)
				this.ErrMsg = this.ErrMsg + "/n图片高度超过限制。请上传高度小于"
						+ this.AllowImgHeight + "px的文件，当前图片高度为"
						+ this.ImgHeight + "px";
		}
		this.ImgFileSize = Math.round(this.ImgObj.fileSize / 1024 * 100) / 100;//取得图片文件的大小  
		alert(this.ImgFileSize);
		if (this.AllowImgFileSize != 0
				&& this.AllowImgFileSize < this.ImgFileSize)
			this.ErrMsg = this.ErrMsg + "/n文件大小超过限制。请上传小于"
					+ this.AllowImgFileSize + "KB的文件，当前文件大小为"
					+ this.ImgFileSize + "KB";
		if (this.ErrMsg != "") {
			this.ShowMsg(this.ErrMsg, false);
			return false;
		} else
			return true;
	}
	UpLoadFileCheck.prototype.ShowMsg = function(msg, tf)//显示提示信息 tf=false 显示错误信息 msg-信息内容 
	{
		alert(msg);
	}
	function sleep(num) {
		var tempDate = new Date();
		var tempStr = "";
		var theXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		while ((new Date() - tempDate) < num) {
			tempStr += "/n" + (new Date() - tempDate);
			try {
				theXmlHttp
						.open("get", "about:blank?JK=" + Math.random(), false);
				theXmlHttp.send();
			} catch (e) {
				;
			}
		}
		//containerDiv.innerText=tempStr;   
		return;
	}
	function c(obj) {
		var d = new UpLoadFileCheck();
		d.IsImg = true;
		d.AllowImgFileSize = 20;
		d.CheckExt(obj);
	}
	</script>

  </head>
  
  <body>
    <h1>${prompt}请您选择需要上传的图片</h1>
   <form action="<%=basePath %>picture/picture_saveAllPic" enctype="multipart/form-data" method="post">
   	
   		<input name="user.userName" value="${user.userName}" type="hidden">
   		<input name="handBook.id" value="${handBook.id}" type="hidden">
		<input name="handBook.userId" value="${handBook.userId}" type="hidden">
		 手册名称：<input name="handBook.name" value="${handBook.name}" type="hidden">${handBook.name}<br>
		 作者名称：<input name="handBook.author" value="${handBook.author}" type="hidden">${handBook.author}<br>
		 公司名称：${user.company}<br>
		 第一张图片：<input type="file" name="uploadPic" onChange="c(this)" id="pic1"/><input name="place" value="no" type="hidden"><br>
		第二张图片：<input type="file" name="uploadPic" onChange="c(this)" id="pic2"/><input name="place" value="no" type="hidden"><br>
		第三张图片：<input type="file" name="uploadPic" onChange="c(this)" id="pic3"/><input name="place" value="no" type="hidden"><br>
		第四张图片：<input type="file" name="uploadPic" onChange="c(this)" id="pic4"/><input name="place" value="no" type="hidden"><br>
		第五张图片：<input type="file" name="uploadPic" onChange="c(this)" id="pic5"/><input name="place" value="no" type="hidden"><br>
		第六张图片：<input type="file" name="uploadPic" onChange="c(this)" id="pic6"/><input name="place" value="no" type="hidden"><br>
		第七张图片：<input type="file" name="uploadPic" onChange="c(this)" id="pic7"/><input name="place" value="no" type="hidden"><br>
		第八张图片：<input type="file" name="uploadPic" onChange="c(this)" id="pic8"/><input name="place" value="no" type="hidden"><br>
		第九张图片：<input type="file" name="uploadPic" onChange="c(this)" id="pic9"/><input name="place" value="no" type="hidden"><br>
		第十张图片：<input type="file" name="uploadPic" onChange="c(this)" id="pic10"/><input name="place" value="no"  type="hidden"><br>
		<input type="submit" value="上传图片">  
		<a href="<%=basePath %>books/books_bookList?handBook.userId=${user.id}">返回列表</a>
   </form>
  </body>
</html>
